home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / misc / frefs11.lha / FetchRefs / Source / GenerateIndex / GUI.c < prev    next >
C/C++ Source or Header  |  1994-10-19  |  20KB  |  663 lines

  1. /**************************************************************************/
  2. /* GUI.c - all opening and handling of the graphic user interface         */
  3. /**************************************************************************/
  4.  
  5. #include "GenerateIndex.h"
  6.  
  7. extern struct TagItem MainOutline[], EditOutline[], OptionsOutline[];
  8. extern struct Library *TritonBase;
  9.  
  10. struct rtFileRequester *DataFileReq, *AddFileReq, *PrefsFileReq;
  11. struct TR_Project *MainPrj, *EditPrj, *OptionsPrj;
  12. struct List EmptyList;
  13.  
  14. BOOL GoOn = TRUE;
  15.  
  16. void
  17. OpenEditWindow(void)
  18. {
  19.     if (!EditPrj)
  20.     {
  21.         TR_SetAttribute(MainPrj, MAIN_EDIT_ID, TRAT_Disabled, TRUE);
  22.         if (EditPrj = TR_OpenProject(Application, EditOutline))
  23.             UpdateMain();
  24.         else
  25.             TR_SetAttribute(MainPrj, MAIN_EDIT_ID, TRAT_Disabled, FALSE);
  26.     }
  27. }
  28.  
  29. void
  30. LockGUI(void)
  31. {
  32.     TR_LockProject(MainPrj);
  33.     if (EditPrj)
  34.         TR_LockProject(EditPrj);
  35.     if (OptionsPrj)
  36.         TR_LockProject(OptionsPrj);
  37. }
  38.  
  39. void
  40. UnlockGUI(void)
  41. {
  42.     TR_UnlockProject(MainPrj);
  43.     if (EditPrj)
  44.         TR_UnlockProject(EditPrj);
  45.     if (OptionsPrj)
  46.         TR_UnlockProject(OptionsPrj);
  47. }
  48.  
  49. void
  50. About(void)
  51. {
  52.      rtEZRequestTags("GenerateIndex " VERSION " " DATE "\n"
  53.                      "Index file generator for FetchRefs\n"
  54.                      "\n"
  55.                      "By Anders Melchiorsen\n"
  56.                      "\n"
  57.                      "FreeWare, 1994",
  58.  
  59.                      "Okay",
  60.  
  61.                      NULL, NULL,
  62.                   
  63.                      RTEZ_Flags, EZREQF_CENTERTEXT,
  64.                      TAG_END,    NULL
  65.                     );
  66. }
  67.  
  68. ULONG
  69. NumOfNodes(struct List *l)
  70. {
  71.     struct Node *n = l->lh_Head;
  72.     ULONG cnt = 0;
  73.  
  74.     while (n->ln_Succ)
  75.     {
  76.         cnt++;
  77.         n = n->ln_Succ;
  78.     }
  79.  
  80.     return(cnt);
  81. }
  82.  
  83. struct FileEntry *
  84. SelectedMain(void)
  85. {
  86.     struct FileEntry *f;
  87.  
  88.     /* Find pointer to selected node in main listview */
  89.     if (IsListEmpty(&FileList))
  90.     {
  91.         f = NULL;
  92.         TR_SetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value, 0);
  93.     } else
  94.     {
  95.         ULONG cnt;
  96.         
  97.         f = (struct FileEntry *)FileList.lh_Head;
  98.         cnt = TR_GetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value);
  99.         while (cnt--)
  100.             f = f->node.ln_Succ;
  101.     }
  102.     return(f);
  103. }
  104.  
  105. struct RefsEntry *
  106. SelectedEdit(void)
  107. {
  108.     struct FileEntry *f = SelectedMain();
  109.     struct RefsEntry *r;
  110.  
  111.     /* Find pointer to selected node in main listview */
  112.     if ((f == NULL) || (IsListEmpty(&f->RefsList)))
  113.     {
  114.         r = NULL;
  115.         TR_SetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value, 0);
  116.     } else
  117.     {
  118.         ULONG cnt;
  119.         
  120.         r = (struct RefsEntry *)f->RefsList.lh_Head;
  121.         cnt = TR_GetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value);
  122.         while (cnt--)
  123.             r = r->node.ln_Succ;
  124.     }
  125.     return(r);
  126. }
  127.  
  128. void
  129. UpdateMain(void)
  130. {
  131.     struct FileEntry *n = SelectedMain();
  132.     
  133.     /* Update main windows 'rescan' and 'delete' gadgets */
  134.     TR_SetAttribute(MainPrj, MAIN_RESCAN_ID, TRAT_Disabled, !n);
  135.     TR_SetAttribute(MainPrj, MAIN_DELETE_ID, TRAT_Disabled, !n);
  136.  
  137.     /* Update main 'references count' gadget */
  138.     TR_SetAttribute(MainPrj, MAIN_REFERENCES_ID, TRAT_Value, n ? NumOfNodes(&n->RefsList) : 0);
  139.  
  140.     /* Update edit 'file' gadget */
  141.     if (EditPrj)
  142.         TR_SetAttribute(EditPrj, EDIT_FILE_ID, TRAT_Text, (ULONG) (n ? (STRPTR)n->Name : (STRPTR)""));
  143.  
  144.     UpdateEdit();
  145. }
  146.  
  147. void
  148. UpdateEdit(void)
  149. {
  150.     static struct FileEntry *shown;
  151.     
  152.     if (EditPrj)
  153.     {
  154.         struct RefsEntry *r = SelectedEdit();
  155.  
  156.         /* Update edit windows 'delete' gadget */
  157.         TR_SetAttribute(EditPrj, EDIT_DELETE_ID, TRAT_Disabled, !r);
  158.         
  159.         /* Update edit windows listview */
  160.         if (SelectedMain() != shown)
  161.         {
  162.             TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, ~0);
  163.             TR_SetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value, 0);
  164.             TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, (ULONG) &EmptyList);
  165.             if (SelectedMain())
  166.                 TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, (ULONG) &SelectedMain()->RefsList);
  167.         }
  168.  
  169.         /* Update edit windows information gadgets */
  170.         TR_SetAttribute(EditPrj, EDIT_NAME_ID, TRAT_Text, (ULONG) (r ? (STRPTR)r->Name : (STRPTR)""));
  171.         TR_SetAttribute(EditPrj, EDIT_OFFSET_ID, TRAT_Value, r ? r->Offset : 0);
  172.         TR_SetAttribute(EditPrj, EDIT_LENGTH_ID, TRAT_Value, r ? r->Length : 0);
  173.         TR_SetAttribute(EditPrj, EDIT_GOTO_ID, TRAT_Value, r ? r->Goto : 0);
  174.  
  175.         shown = SelectedMain();
  176.     } else
  177.         shown = (APTR)-1;
  178. }
  179.  
  180. void
  181. UpdateOptions(void)
  182. {
  183.     TR_SetAttribute(OptionsPrj, OPTIONS_AUTODOC_ID,         TRAT_Value, Settings.AutoDocPrf.Active);
  184.  
  185.     TR_SetAttribute(OptionsPrj, OPTIONS_C_ID,               TRAT_Value, Settings.CPrf.Active);
  186.     TR_SetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID,        TRAT_Value, Settings.CPrf.Define);
  187.     TR_SetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID,        TRAT_Value, Settings.CPrf.Struct);
  188.     TR_SetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID,       TRAT_Value, Settings.CPrf.Typedef);
  189.  
  190.     TR_SetAttribute(OptionsPrj, OPTIONS_E_ID,               TRAT_Value, Settings.EPrf.Active);
  191.     TR_SetAttribute(OptionsPrj, OPTIONS_E_CONST_ID,         TRAT_Value, Settings.EPrf.Const);
  192.     TR_SetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID,        TRAT_Value, Settings.EPrf.Object);
  193.     TR_SetAttribute(OptionsPrj, OPTIONS_E_PROC_ID,          TRAT_Value, Settings.EPrf.Proc);
  194.  
  195.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_ID,             TRAT_Value, Settings.AsmPrf.Active);
  196.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID,         TRAT_Value, Settings.AsmPrf.Equ);
  197.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID,   TRAT_Value, Settings.AsmPrf.Structure);
  198.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID,       TRAT_Value, Settings.AsmPrf.Macro);
  199.  
  200.     TR_SetAttribute(OptionsPrj, OPTIONS_RECURSIVELY_ID,     TRAT_Value, Settings.Recursively);
  201.     TR_SetAttribute(OptionsPrj, OPTIONS_KEEPEMPTY_ID,       TRAT_Value, Settings.KeepEmpty);
  202.     TR_SetAttribute(OptionsPrj, OPTIONS_UNKNOWNFILES_ID,    TRAT_Value, Settings.UnknownFiles);
  203.  
  204.     UpdateOptionsGhost();
  205. }
  206.  
  207. void
  208. UpdateOptionsGhost(void)
  209. {
  210.     BOOL ghost;
  211.  
  212.     if (!OptionsPrj)
  213.         return;
  214.     
  215.     ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_C_ID, TRAT_Value);
  216.     TR_SetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID,        TRAT_Disabled, ghost);
  217.     TR_SetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID,        TRAT_Disabled, ghost);
  218.     TR_SetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID,       TRAT_Disabled, ghost);
  219.  
  220.     ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_E_ID, TRAT_Value);
  221.     TR_SetAttribute(OptionsPrj, OPTIONS_E_CONST_ID,         TRAT_Disabled, ghost);
  222.     TR_SetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID,        TRAT_Disabled, ghost);
  223.     TR_SetAttribute(OptionsPrj, OPTIONS_E_PROC_ID,          TRAT_Disabled, ghost);
  224.  
  225.     ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_ASM_ID, TRAT_Value);
  226.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID,         TRAT_Disabled, ghost);
  227.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID,   TRAT_Disabled, ghost);
  228.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID,       TRAT_Disabled, ghost);
  229. }
  230.  
  231. void
  232. UpdateSettingsStruct(void)
  233. {
  234.     Settings.AutoDocPrf.Active  = TR_GetAttribute(OptionsPrj, OPTIONS_AUTODOC_ID,         TRAT_Value);
  235.  
  236.     Settings.CPrf.Active        = TR_GetAttribute(OptionsPrj, OPTIONS_C_ID,               TRAT_Value);
  237.     Settings.CPrf.Define        = TR_GetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID,        TRAT_Value);
  238.     Settings.CPrf.Struct        = TR_GetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID,        TRAT_Value);
  239.     Settings.CPrf.Typedef       = TR_GetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID,       TRAT_Value);
  240.  
  241.     Settings.EPrf.Active        = TR_GetAttribute(OptionsPrj, OPTIONS_E_ID,               TRAT_Value);
  242.     Settings.EPrf.Const         = TR_GetAttribute(OptionsPrj, OPTIONS_E_CONST_ID,         TRAT_Value);
  243.     Settings.EPrf.Object        = TR_GetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID,        TRAT_Value);
  244.     Settings.EPrf.Proc          = TR_GetAttribute(OptionsPrj, OPTIONS_E_PROC_ID,          TRAT_Value);
  245.  
  246.     Settings.AsmPrf.Active      = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_ID,             TRAT_Value);
  247.     Settings.AsmPrf.Equ         = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID,         TRAT_Value);
  248.     Settings.AsmPrf.Structure   = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID,   TRAT_Value);
  249.     Settings.AsmPrf.Macro       = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID,       TRAT_Value);
  250.  
  251.     Settings.Recursively        = TR_GetAttribute(OptionsPrj, OPTIONS_RECURSIVELY_ID,     TRAT_Value);
  252.     Settings.KeepEmpty          = TR_GetAttribute(OptionsPrj, OPTIONS_KEEPEMPTY_ID,       TRAT_Value);
  253.     Settings.UnknownFiles       = TR_GetAttribute(OptionsPrj, OPTIONS_UNKNOWNFILES_ID,    TRAT_Value);
  254. }
  255.  
  256. void
  257. HandleListViewClick(struct TR_Message *m)
  258. {
  259.     if (m->trm_Project == MainPrj)
  260.     {
  261.         UpdateMain();
  262.         if (m->trm_Qualifier & IEQUALIFIER_REPEAT)
  263.             OpenEditWindow();
  264.     }
  265.     else if (m->trm_Project == EditPrj)
  266.         UpdateEdit();
  267. }
  268.  
  269. void
  270. HandleMenu(struct TR_Message *m)
  271. {
  272.     switch (m->trm_ID)
  273.     {
  274.         case MAIN_MENU_PROJECT_CLEAR:
  275.             LockGUI();
  276.             if (rtEZRequestTags("Really clear the entire list?",
  277.                                 "_Okay|_Cancel",
  278.                                 NULL, NULL,
  279.                                     
  280.                                 RT_Underscore, '_',
  281.                                 TAG_END))
  282.             {
  283.                 ClearFileList();
  284.                 TR_SetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value, 0);
  285.                 TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG)&FileList);
  286.                 UpdateMain();
  287.             }
  288.             UnlockGUI();
  289.         break;
  290.  
  291.         case MAIN_MENU_PROJECT_LOAD:
  292.             LockGUI();
  293.             if (!IsListEmpty(&FileList))
  294.             {
  295.                 ULONG ret;
  296.  
  297.                 ret = rtEZRequestTags(  "Current list is not empty!",
  298.                                         "_Replace|_Append|_Cancel",
  299.                                         NULL, NULL,
  300.                                         
  301.                                         RT_Underscore, '_',
  302.                                         TAG_END);
  303.  
  304.                 if (ret == 0)
  305.                 {
  306.                     UnlockGUI();
  307.                     break;
  308.                 }
  309.  
  310.                 if (ret == 1)
  311.                 {
  312.                     ClearFileList();
  313.                     TR_SetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value, 0);
  314.                     TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG)&FileList);
  315.                     UpdateMain();
  316.                 }
  317.             }
  318.  
  319.             LoadData(NULL);
  320.             TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG)&FileList);
  321.             UpdateMain();
  322.             UnlockGUI();
  323.         break;
  324.  
  325.         case MAIN_MENU_PROJECT_SAVE:
  326.             LockGUI();
  327.             SaveData(NULL);
  328.             UnlockGUI();
  329.         break;
  330.  
  331.         case MAIN_MENU_PROJECT_OPTIONS:
  332.             if (!OptionsPrj)
  333.             {
  334.                 TR_SetAttribute(MainPrj, MAIN_ADD_ID, TRAT_Disabled, TRUE);
  335.                 if (OptionsPrj = TR_OpenProject(Application, OptionsOutline))
  336.                     UpdateOptions();
  337.                 else
  338.                     TR_SetAttribute(MainPrj, MAIN_ADD_ID, TRAT_Disabled, FALSE);
  339.             }
  340.         break;
  341.  
  342.         case MAIN_MENU_PROJECT_ABOUT:
  343.             LockGUI();
  344.             About();
  345.             UnlockGUI();
  346.         break;
  347.  
  348.         case MAIN_MENU_PROJECT_QUIT:
  349.             GoOn = FALSE;
  350.         break;
  351.     }
  352. }
  353.  
  354. void
  355. HandleMainIDCMP(struct TR_Message *m)
  356. {
  357.     if (m->trm_Class == TRMS_CLOSEWINDOW)
  358.     {
  359.         GoOn = FALSE;
  360.         return;
  361.     }
  362.     
  363.     HandleMenu(m);
  364.  
  365.     /* Check for gadgets */
  366.     switch (m->trm_ID)
  367.     {
  368.         case MAIN_ADD_ID:
  369.             struct rtFileList *selfiles;
  370.             char tmpname[108];
  371.  
  372.             LockGUI();
  373.             if (selfiles = rtFileRequest(AddFileReq, tmpname,
  374.                               "Index files...",
  375.  
  376.                               RTFI_Flags,    FREQF_MULTISELECT | FREQF_SELECTDIRS,
  377.                               TAG_END))
  378.             {
  379.                 TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, ~0);
  380.                 IndexFileList(AddFileReq->Dir, selfiles);
  381.                 rtFreeFileList(selfiles);
  382.                 TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG) &FileList);
  383.                 UpdateMain();
  384.             }
  385.             UnlockGUI();
  386.         break;
  387.         
  388.         case MAIN_EDIT_ID:
  389.             OpenEditWindow();
  390.         break;
  391.  
  392.         case MAIN_RESCAN_ID:
  393.             struct FileEntry *f;
  394.  
  395.             if (f = SelectedMain())
  396.             {
  397.                 struct Node *new, *last = GetTail(&FileList);
  398.  
  399.                 IndexFile("", f->Name);
  400.                 new = GetTail(&FileList);
  401.                 
  402.                 /* If rescan added an item to the file list */
  403.                 if (new != last)
  404.                 {
  405.                     struct Node *new;
  406.  
  407.                     TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, ~0);
  408.                     
  409.                     /* Attach new list */
  410.                     new = GetTail(&FileList);
  411.                     Remove(new);
  412.                     Insert(&FileList, new, &f->node);
  413.  
  414.                     /* Free old list */
  415.                     while (new = RemHead(&f->RefsList))
  416.                         FreeVec(new);
  417.                     Remove(&f->node);
  418.                     FreeVec(f);
  419.  
  420.                     TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG) &FileList);
  421.                     UpdateMain();
  422.  
  423.                     break;
  424.                 } /* else fall through to Delete gadget */
  425.             }
  426.  
  427.         case MAIN_DELETE_ID:
  428.             struct FileEntry *f;
  429.  
  430.             if (f = SelectedMain())
  431.             {
  432.                 struct Node *n;
  433.                 ULONG num = TR_GetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value);
  434.  
  435.                 TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, ~0);
  436.                 if (num && (num + 1 == NumOfNodes(&FileList)))
  437.                     TR_SetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value, num - 1);
  438.  
  439.                 while (n = RemHead(&f->RefsList))
  440.                     FreeVec(n);
  441.  
  442.                 Remove(&f->node);
  443.                 FreeVec(f);
  444.  
  445.                 TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG) &FileList);
  446.                 UpdateMain();
  447.             }
  448.         break;
  449.     }
  450. }
  451.  
  452. void
  453. HandleEditIDCMP(struct TR_Message *m)
  454. {
  455.     if (m->trm_Class == TRMS_ACTION)
  456.     {
  457.         if (m->trm_ID == EDIT_OKAY_ID)
  458.         {
  459.             TR_CloseProject(EditPrj);
  460.             EditPrj = NULL;
  461.             TR_SetAttribute(MainPrj, MAIN_EDIT_ID, TRAT_Disabled, FALSE);
  462.         } else if (m->trm_ID == EDIT_DELETE_ID)
  463.         {
  464.             struct RefsEntry *r;
  465.  
  466.             if (r = SelectedEdit())
  467.             {
  468.                 ULONG num = TR_GetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value);
  469.  
  470.                 TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, ~0);
  471.                 if (num && (num + 1 == NumOfNodes(&SelectedMain()->RefsList)))
  472.                     TR_SetAttribute(EditPrj, EDIT_LIST_ID, TRAT_Value, num - 1);
  473.  
  474.                 Remove(&r->node);
  475.                 FreeVec(r);
  476.  
  477.                 TR_SetAttribute(EditPrj, EDIT_LIST_ID, NULL, (ULONG) &SelectedMain()->RefsList);
  478.             }
  479.         }
  480.         UpdateMain();
  481.     }
  482. }
  483.  
  484. void
  485. HandleOptionsIDCMP(struct TR_Message *m)
  486. {
  487.     static UBYTE prefname[108];
  488.  
  489.     if ((m->trm_Class == TRMS_CLOSEWINDOW) || (m->trm_Class == TRMS_ACTION && m->trm_ID == OPTIONS_CANCEL_ID))
  490.     {
  491.         TR_CloseProject(OptionsPrj);
  492.         OptionsPrj = NULL;
  493.         TR_SetAttribute(MainPrj, MAIN_ADD_ID, TRAT_Disabled, FALSE);
  494.     }
  495.  
  496.     if (m->trm_Class == TRMS_ACTION)
  497.     {
  498.         if (m->trm_ID == OPTIONS_USE_ID || m->trm_ID == OPTIONS_SAVE_ID)
  499.         {
  500.             UpdateSettingsStruct();
  501.  
  502.             if (m->trm_ID == OPTIONS_SAVE_ID)
  503.                 SaveSettings("ENVARC:FetchRefs_GI.prefs");
  504.             SaveSettings("ENV:FetchRefs_GI.prefs");
  505.  
  506.             TR_CloseProject(OptionsPrj);
  507.             OptionsPrj = NULL;
  508.             TR_SetAttribute(MainPrj, MAIN_ADD_ID, TRAT_Disabled, FALSE);
  509.         }
  510.  
  511.         if (m->trm_ID == OPTIONS_MENU_PROJECT_OPEN_ID)
  512.         {
  513.             if (rtFileRequest(PrefsFileReq, prefname,
  514.                               "Load settings...",
  515.  
  516.                               TAG_END))
  517.             {
  518.                 BPTR newdir, olddir;
  519.                 
  520.                 if (newdir = Lock(PrefsFileReq->Dir, SHARED_LOCK))
  521.                 {
  522.                     struct Prefs tmpsettings;
  523.  
  524.                     CopyMem(&Settings, &tmpsettings, sizeof(struct Prefs));
  525.                     olddir = CurrentDir(newdir);
  526.                     LoadSettings(prefname);
  527.                     CurrentDir(olddir);
  528.                     UnLock(newdir);
  529.                     UpdateOptions();
  530.                     CopyMem(&tmpsettings, &Settings, sizeof(struct Prefs));
  531.                 }
  532.             }
  533.         }
  534.         
  535.         if (m->trm_ID == OPTIONS_MENU_PROJECT_SAVEAS_ID)
  536.         {
  537.             if (rtFileRequest(PrefsFileReq, prefname,
  538.                               "Save settings...",
  539.  
  540.                               RTFI_Flags,    FREQF_SAVE,
  541.                               TAG_END))
  542.             {
  543.                 BPTR newdir, olddir;
  544.                 
  545.                 if (newdir = Lock(PrefsFileReq->Dir, SHARED_LOCK))
  546.                 {
  547.                     struct Prefs tmpsettings;
  548.  
  549.                     CopyMem(&Settings, &tmpsettings, sizeof(struct Prefs));
  550.                     UpdateSettingsStruct();
  551.                     olddir = CurrentDir(newdir);
  552.                     SaveSettings(prefname);
  553.                     CurrentDir(olddir);
  554.                     UnLock(newdir);
  555.                     CopyMem(&tmpsettings, &Settings, sizeof(struct Prefs));
  556.                 }
  557.             }
  558.         }
  559.     }
  560.  
  561.     if (m->trm_Class = TRMS_NEWVALUE)
  562.         UpdateOptionsGhost();
  563. }
  564.  
  565. void
  566. HandleGUI(void)
  567. {
  568.     struct TR_Message *msg;
  569.  
  570.     while (GoOn)
  571.     {
  572.         TR_Wait(Application, NULL);
  573.  
  574.         while (msg = TR_GetMsg(Application))
  575.         {
  576.             if (msg->trm_Class == TRMS_NEWVALUE)
  577.                 HandleListViewClick(msg);
  578.  
  579.             if (msg->trm_Project == MainPrj)
  580.                 HandleMainIDCMP(msg);
  581.             else if (msg->trm_Project == EditPrj)
  582.                 HandleEditIDCMP(msg);
  583.             else if (msg->trm_Project == OptionsPrj)
  584.                 HandleOptionsIDCMP(msg);
  585.  
  586.             TR_ReplyMsg(msg);
  587.         }
  588.     }
  589. }
  590.  
  591. void
  592. GoGUI(void)
  593. {
  594.     NewList(&EmptyList);
  595.     
  596.     if (!ReqToolsBase)
  597.         CloseGUI();
  598.     
  599.     if (!TR_OpenTriton(2,
  600.             TRCA_Name,      "GenerateIndex",
  601.             TRCA_LongName,  "FetchRefs' GenerateIndex",
  602.             TRCA_Info,      "Index file generator for FetchRefs",
  603.             TRCA_Version,   VERSION,
  604.             TRCA_Release,   VERSION,
  605.             TRCA_Date,      __COMMODORE_DATE__,
  606.             TAG_END))
  607.         CloseGUI();
  608.  
  609.     if (!(DataFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
  610.         CloseGUI();
  611.  
  612.     if (!(AddFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
  613.         CloseGUI();
  614.  
  615.     if (!(PrefsFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
  616.         CloseGUI();
  617.  
  618.     if (InitialFile)
  619.     {
  620.         LoadData(InitialFile);
  621.         strcpy(DataName, FilePart(InitialFile));
  622.         if (PathPart(InitialFile) != InitialFile)
  623.         {
  624.             *(PathPart(InitialFile)) = 0;
  625.             rtChangeReqAttr(DataFileReq, RTFI_Dir, InitialFile, TAG_END);
  626.         }
  627.     }
  628.  
  629.     if (!(MainPrj = TR_OpenProject(Application, MainOutline)))
  630.         CloseGUI();
  631.  
  632.     TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG)&FileList);
  633.     UpdateMain();
  634.  
  635.     HandleGUI();
  636.     CloseGUI();
  637. }
  638.  
  639. void
  640. CloseGUI(void)
  641. {
  642.     if (ReqToolsBase)
  643.     {
  644.         rtFreeRequest(DataFileReq);
  645.         rtFreeRequest(AddFileReq);
  646.         rtFreeRequest(PrefsFileReq);
  647.     } else
  648.         CloseAll(ERROR_SPECIAL, "You need ReqTools version 38+ for the GUI!");
  649.  
  650.     if (TritonBase)
  651.     {
  652.         if (OptionsPrj)
  653.             TR_CloseProject(OptionsPrj);
  654.         if (EditPrj)
  655.             TR_CloseProject(EditPrj);
  656.         if (MainPrj)
  657.             TR_CloseProject(MainPrj);
  658.         TR_CloseTriton();
  659.     } else
  660.         CloseAll(ERROR_SPECIAL, "You need Triton version 2+ for the GUI!");
  661. }
  662.  
  663.